package com.ttg.web.dao.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ttg.common.dto.TagProducer;
import com.ttg.common.entities.BasePage;
import com.ttg.model.dto.VipDetailDto;
import com.ttg.model.mapper.BankCardBindingInfoMapper;
import com.ttg.model.pojo.BankCardBindingInfo;
import com.ttg.web.dao.BankCardBindingInfoDao;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class BankCardBindingInfoDaoImpl extends ServiceImpl<BankCardBindingInfoMapper, BankCardBindingInfo> implements BankCardBindingInfoDao {
    @Override
    public List<BankCardBindingInfo> getByCstId(String cstId) {

        return baseMapper.getByCstId(cstId);
    }

    @Override
    public BankCardBindingInfo getByBankNoAndProduct(String bankCardNumber, String bindingCardProduct) {
        LambdaQueryWrapper<BankCardBindingInfo> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(BankCardBindingInfo::getBankCardNumber, bankCardNumber)
                .eq(BankCardBindingInfo::getBindingCardProduct, bindingCardProduct);
        return getOne(queryWrapper);
    }

    @Override
    public List<BankCardBindingInfo> listByBankNoAndProduct(String bankCardNumber, String bindingCardProduct) {
        LambdaQueryWrapper<BankCardBindingInfo> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(BankCardBindingInfo::getBankCardNumber, bankCardNumber)
                .eq(BankCardBindingInfo::getBindingCardProduct, bindingCardProduct);
        return list(queryWrapper);
    }

    @Override
    public Map<String, Long> mapByBankNoAndProduct(String bankCardNumber, String bindingCardProduct) {
        LambdaQueryWrapper<BankCardBindingInfo> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(BankCardBindingInfo::getBankCardNumber, bankCardNumber)
                .eq(BankCardBindingInfo::getBindingCardProduct, bindingCardProduct);
        Map<String, Long> map = new HashMap<>();
        for (BankCardBindingInfo bankCardBindingInfo : list(queryWrapper)) {
            map.put(bankCardBindingInfo.getBankCardNumber() + bankCardBindingInfo.getBindingCardProduct() + "", bankCardBindingInfo.getId());
        }

//        map =  baseMapper.mapByBankNoAndProduct(bankCardNumber,bindingCardProduct);
        return map;
    }


    @Override
    public Map<String, Long> existsMapByBankNoAndProduct(List<Map<String, String>> existsWhere) {
        if (CollectionUtils.isEmpty(existsWhere)) {
            return Collections.emptyMap();
        }
        Map<String, Long> rsMap = new HashMap<>();
        for (BankCardBindingInfo bindingInfoList : baseMapper.existsMapByBankNoAndProduct(existsWhere)) {
            rsMap.put(bindingInfoList.getBankCardNumber() + bindingInfoList.getBindingCardProduct(), bindingInfoList.getId());
        }

        return rsMap;
    }

    @Override
    public List<Long> getVipIdsByTags(List<TagProducer> tags, String key) {
        return baseMapper.getVipIdsByTags(tags,key);
    }


}
